package com.yima.baseproj.module.app.resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yima.baseproj.module.app.resource.model.*;
import com.yima.baseproj.module.app.resource.model.AppResourceAddParamModel;
import com.yima.baseproj.module.app.resource.model.AppResourceEditParamModel;
import com.yima.baseproj.module.app.resource.model.AppResourceSearchModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class AppResourceService extends ServiceImpl<AppResourceMapper, AppResourceEntity> {

    public Page<Map> findByPage(Page page, AppResourceSearchModel searchVo) {
        return baseMapper.findBySearchVo(page,searchVo);
    }

    public List<Map> findByList(AppResourceSearchModel searchVo) {
        return baseMapper.findBySearchVo(searchVo);
    }

    /**
     * 添加 - 事务
     * @param paramModel
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(AppResourceAddParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void edit(AppResourceEditParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void del(String id) {
        removeById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public void dels(String[] ids) {
        removeByIds(Arrays.asList(ids));
    }

    public AppResourceEntity findByType(String type) {
        return getOne(Wrappers.<AppResourceEntity>query().eq("type",type));
    }
}